package com.fuja.swf.model;

import waba.io.*;


/**
 * Title:
 * Description:  
 * Copyright:    Copyright (c) 2004
 * Company:      InformaXXIma Processamento de Dados
 * www.informaxxima.com.br
 * @author Renan Bundt
 * @version 1.0
 */

public class EasyCatalog extends Catalog
{
      private byte [] b;
      
      
      public EasyCatalog(String creator, int type)
      {
            super(creator,type);
      }

      public String read(int recordPos) // to read you only need to inform the record position
      {
            setRecordPos(recordPos);
            int f = getRecordSize();
            b = new byte[f];
            readBytes(b, 0, f);
            return new String(b);
      }

      public byte[] getByteArray() // use by the class
      {
            return b;
      }



	/* 
	* In the method 'add', you can add new records and/or update records
	* To add a record do this: add(0, "add this", "I"); 
	* "I" - 'I'nsert a record
	* To update a record do this: 
	* 	int i = YOURTCATALOG.getRecordPos();
	*	add(i, "add this", "U"); 
	* "U" - 'U'pdate a record
	*/
      public int add(int recordPos, String s, String function)  
      {
            if (function.equals("I"))   
            	recordPos = addRecord(s.length());

            setRecordPos(recordPos);
            return writeBytes(s.getBytes(), 0, s.length());
      }
      
      public void delete(int recordPos)
      {
            setRecordPos(recordPos);
            deleteRecord();
      }
}